<template>
  <div class="home">
      <home-header/>
      <home-swiper :list="swiperList" />
      <home-icons :list="iconList" />
      <home-recommend :list="recommendList" />
      <home-weekend :list="weekendList" />
  </div>
</template>

<script>
import axios from 'axios'
import HomeHeader from './components/Header'
import HomeSwiper from './components/Swiper'
import HomeIcons from './components/Icons'
import HomeRecommend from './components/recommend'
import HomeWeekend from './components/weekend'
import { mapState } from 'vuex'
export default {
  name: 'Home',
  components: {
    HomeHeader,
    HomeSwiper,
    HomeIcons,
    HomeRecommend,
    HomeWeekend
  },
  data () {
    return {
      swiperList: [],
      iconList: [],
      recommendList: [],
      weekendList: []
    }
  },
  computed: {
    ...mapState(['city'])
  },
  methods: {
    getHomeInfo () {
      return axios.get('api/index.json?city=' + this.city).then((res) => {
        if (res.status === 200) {
          return Promise.resolve(res.data)
        } else {
          return Promise.reject(res)
        }
      })
    }
  },
  mounted () {
    this.getHomeInfo().then((res) => {
      if (res.ret === true) {
        res = res.data
        this.swiperList = res.swiperList
        this.iconList = res.iconList
        this.recommendList = res.recommendList
        this.weekendList = res.weekendList
      }
    })
  },
  activated () {
    this.getHomeInfo().then((res) => {
      if (res.ret === true) {
        res = res.data
        this.swiperList = res.swiperList
        this.iconList = res.iconList
        this.recommendList = res.recommendList
        this.weekendList = res.weekendList
      }
    })
  }
}
</script>
